/*
 * @Author: zhangweinan
 * @Date: 2023-07-17 14:27:07
 * @LastEditors: Hzt
 * @LastEditTime: 2025-07-11 17:25:35
 * @Description: file content
 * @FilePath: \cty_admin\src\api\useManage.js
 */
import { post, get } from "@/utils/request";

//获取菜单列表
export function fetchMenuList(params) {
  return get("/menu/treeSelectList", params);
}

// 创建角色
export function fetchCreateUser(data) {
  return post("/user/save", data);
}

//创建菜单
export function fetchCreateMenu(data) {
  return post("/menu/save", data);
}

//删除菜单
export function fetchDeleteMenu(id) {
  return post(`/menu/delete?id=${id}`);
}

//查询菜单详情
export function fetchMenuDetail(id) {
  return get(`/menu/getInfo?id=${id}`);
}
//获取角色列表
export function fetchRoleList(params) {
  return get("/role/treeSelectList", params);
}

//查询用户详情
export function fetchUserDetail(id) {
  return get(`/user/getInfo?id=${id}`);
}

//保存角色
export function fetchSaveRole(data) {
  return post("/role/save", data);
}

//查询角色详情
export function fetchRoleDetail(id) {
  return get(`/role/getInfo?id=${id}`);
}

//删除角色
export function fetchDeleteRole(id) {
  return post(`/role/delete?id=${id}`);
}

//获取等级列表
export function fetchLevelList(params) {
  return get("/grade/getList", params);
}

//新增等级
export function fetchCreateLevel(data) {
  return post("/grade/add", data);
}

//删除等级
export function fetchDeleteLevel(data) {
  return post(`/grade/deletedLevel?level=${data.level}`);
}

//同步等级信息
export function fetchSyncLevel(level) {
  return post(`/grade/syncGrade?level=${level}`);
}

//修改用户推荐人
export function fetchUpdateReferrer(params) {
  return post(
    `/user/changeReferrer?id=${params.id}&referrerId=${params.referrerId}`
  );
}
export function fetchUpdateService(data) {
  return post(
    `/user/changeServiceUser`,
    data
  );
}

export function fetchUpdateServiceTeam(data) {
  return post(
    `/user/team/changeServiceUser`,
    data
  );
}
//修改团队
export function fetchUpdateTeam(data) {
  return post(`user/moveToTeam`, data);
}

//修改密码
export function fetchUpdatePassword(params) {
  return post(`/user/uP?o=${params.o}&n=${params.n}`);
}

//重置密码
export function fetchResetPassword(id) {
  return post(`/user/restP?userId=${id}`);
}
//获取验证码
export function getValidateCode(data) {
  return post('/sms/validateCode', data);
}
//重置密码
export function resetPassWord(data) {
  return post('/user/resetPassWord', data);
}
//修改或者添加个人账户信息
export function updateUserAccount(data) {
  return post('/user/bankAccount/saveAdminBankAccount', data);
}
//获取个人实名信息
export function fetchRealAuthInfo(userId) {
  return get(`/user/personRealName/getDetailRealInfo?userId=${userId}`)
  .then(res => {
    // 确保返回数据结构正确
    return {
      ...res,
      data: res.data || { 
        realName: '',
        idCardNo: '',
        phoneNumber: '' 
      }
    };
  });
}
//获取公司认证信息
export function fetchCompanyAuthInfo(userId) {
  return get(`/user/companyReal/getDetailInfo?userId=${userId}`)
  .then(res => ({
    ...res,
    data: res.data || { companyName: '' }  // 添加默认公司信息
  }));
}
//获取个人账户信息
export function fetchUserAccounts(userId) {
  return get(`/user/bankAccount/listDetail?userId=${userId}`)
  .then(res => ({
    ...res,
    data: res.data || []  // 确保始终返回数组
  }));
}
 